package com.pajk.user.model;

import com.pajk.user.model.enums.*;

import java.io.Serializable;
import java.util.Date;

/**
 *
 * @author Haomin Liu
 */
public class User extends Entity
                  implements Serializable {

    private Long id;
    private Long mobile;//手机号
    private String password;//密码
    private String nick;//昵称
    private Gender gender;//性别
    private String avatar;//头像URL

    private String wanliId;//万里通账号
    private String yizhangId;//一账通账号

    private CertificationType certType;
    private String certId;//身份证号

    private Integer credits = 0;//健康积分
    private Integer wanliCredits = 0;//万里通积分

    private Date birthday;//出生日期
    private Integer height;//身高单位cm
    private Integer weight;//体重单位g
    private String physique;//体质   多种体质以,号分隔

    private BloodType bloodType;//血型
    private Role role;
    private UserStatus userStatus;

    /**
     * 设计约定：务必保证默认构造函数生成的对象中所有域都是null。
     * UserService的Update接口靠域是否位空来判断是否需要更新。
     */
    public User(){}

    public User(Long id) {
        this.id = id;
    }

    public User(User rhs){
        id = rhs.id;
        mobile = rhs.mobile;
        password = rhs.password;
        nick = rhs.nick;
        gender = rhs.gender;
        avatar = rhs.avatar;
        wanliId = rhs.wanliId;
        yizhangId = rhs.yizhangId;
        certType = rhs.certType;
        certId = rhs.certId;
        credits = rhs.credits;
        wanliCredits = rhs.wanliCredits;
        birthday = rhs.birthday;
        height = rhs.height;
        weight = rhs.weight;
        physique = rhs.physique;
        bloodType = rhs.bloodType;
        role = rhs.role;
        userStatus = rhs.userStatus;
        gmtCreate = rhs.gmtCreate;
        gmtUpdate = rhs.gmtUpdate;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public Long getId() {
        return id;
    }

    protected void setId(Long id) {
        this.id = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Long getMobile() {
        return mobile;
    }

    protected void setMobile(Long mobile) {
        this.mobile = mobile;
    }

    public String getWanliId() {
        return wanliId;
    }

    public void setWanliId(String wanliId) {
        this.wanliId = wanliId;
    }

    public String getYizhangId() {
        return yizhangId;
    }

    public void setYizhangId(String yizhangId) {
        this.yizhangId = yizhangId;
    }

    public CertificationType getCertType() {
        return certType;
    }

    public void setCertType(CertificationType certType) {
        this.certType = certType;
    }

    public String getCertId() {
        return certId;
    }

    public void setCertId(String certId) {
        this.certId = certId;
    }

    public Integer getCredits() {
        return credits;
    }

    protected void setCredits(Integer credits) {
        this.credits = credits;
    }

    public Integer getWanliCredits() {
        return wanliCredits;
    }

    protected void setWanliCredits(Integer wanliCredits) {
        this.wanliCredits = wanliCredits;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public Integer getWeight() {
        return weight;
    }

    public String getNick() {
        return nick;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    public String getPhysique() {
        return physique;
    }

    public void setPhysique(String physique) {
        this.physique = physique;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public UserStatus getUserStatus() {
        return userStatus;
    }

    public BloodType getBloodType() {
        return bloodType;
    }

    public void setBloodType(BloodType bloodType) {
        this.bloodType = bloodType;
    }

    protected void setUserStatus(UserStatus userStatus) {
        this.userStatus = userStatus;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("User{");
        sb.append("id=").append(id);
        sb.append(", mobile=").append(mobile);
        sb.append(", password='").append(password).append('\'');
        sb.append(", nick='").append(nick).append('\'');
        sb.append(", gender=").append(gender);
        sb.append(", avatar='").append(avatar).append('\'');
        sb.append(", wanliId='").append(wanliId).append('\'');
        sb.append(", yizhangId='").append(yizhangId).append('\'');
        sb.append(", certType=").append(certType);
        sb.append(", certId='").append(certId).append('\'');
        sb.append(", credits=").append(credits);
        sb.append(", wanliCredits=").append(wanliCredits);
        sb.append(", birthday=").append(birthday);
        sb.append(", height=").append(height);
        sb.append(", weight=").append(weight);
        sb.append(", physique='").append(physique).append('\'');
        sb.append(", bloodType=").append(bloodType);
        sb.append(", role=").append(role);
        sb.append(", userStatus=").append(userStatus);
        sb.append('}');
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof User)) return false;

        User user = (User) o;

        if (avatar != null ? !avatar.equals(user.avatar) : user.avatar != null) return false;
        if (birthday != null ? !birthday.equals(user.birthday) : user.birthday != null) return false;
        if (bloodType != user.bloodType) return false;
        if (certId != null ? !certId.equals(user.certId) : user.certId != null) return false;
        if (certType != user.certType) return false;
        if (credits != null ? !credits.equals(user.credits) : user.credits != null) return false;
        if (gender != user.gender) return false;
        if (height != null ? !height.equals(user.height) : user.height != null) return false;
        if (id != null ? !id.equals(user.id) : user.id != null) return false;
        if (mobile != null ? !mobile.equals(user.mobile) : user.mobile != null) return false;
        if (nick != null ? !nick.equals(user.nick) : user.nick != null) return false;
        if (password != null ? !password.equals(user.password) : user.password != null) return false;
        if (physique != null ? !physique.equals(user.physique) : user.physique != null) return false;
        if (role != user.role) return false;
        if (userStatus != user.userStatus) return false;
        if (wanliCredits != null ? !wanliCredits.equals(user.wanliCredits) : user.wanliCredits != null) return false;
        if (wanliId != null ? !wanliId.equals(user.wanliId) : user.wanliId != null) return false;
        if (weight != null ? !weight.equals(user.weight) : user.weight != null) return false;
        if (yizhangId != null ? !yizhangId.equals(user.yizhangId) : user.yizhangId != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (mobile != null ? mobile.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (nick != null ? nick.hashCode() : 0);
        result = 31 * result + (gender != null ? gender.hashCode() : 0);
        result = 31 * result + (avatar != null ? avatar.hashCode() : 0);
        result = 31 * result + (wanliId != null ? wanliId.hashCode() : 0);
        result = 31 * result + (yizhangId != null ? yizhangId.hashCode() : 0);
        result = 31 * result + (certType != null ? certType.hashCode() : 0);
        result = 31 * result + (certId != null ? certId.hashCode() : 0);
        result = 31 * result + (credits != null ? credits.hashCode() : 0);
        result = 31 * result + (wanliCredits != null ? wanliCredits.hashCode() : 0);
        result = 31 * result + (birthday != null ? birthday.hashCode() : 0);
        result = 31 * result + (height != null ? height.hashCode() : 0);
        result = 31 * result + (weight != null ? weight.hashCode() : 0);
        result = 31 * result + (physique != null ? physique.hashCode() : 0);
        result = 31 * result + (bloodType != null ? bloodType.hashCode() : 0);
        result = 31 * result + (role != null ? role.hashCode() : 0);
        result = 31 * result + (userStatus != null ? userStatus.hashCode() : 0);
        return result;
    }
}
